package com.example.design.newfeature;

import java.util.Arrays;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.stream.Collectors;

/**
 * \* @author: bear
 * \* Date: 2021-02-07-10:34
 * \* describe:
 */
public class Test {
	public static void main(String[] args) {
		List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");
		// 计算空字符串
		long count = strings.stream().filter(string -> string.isEmpty()).count();
		System.out.println(count);

		//字符串等于3的数量
		strings.stream().filter(x->x.length()==3).count();
		// 删除空字符串
		strings.stream().filter(x->!x.isEmpty()).collect(Collectors.toList());
		// 删除空字符串，并使用逗号把它们合并起来
		strings.stream().filter(x->!x.isEmpty()).collect(Collectors.joining(","));

		List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);
		// 获取列表元素平方数
		numbers.stream().map(i->i*i).distinct().collect(Collectors.toList());
		// 输出10个随机数
		List<Integer> integers = Arrays.asList(1,2,13,4,15,6,17,8,19);

		IntSummaryStatistics stats = integers.stream().mapToInt((x) -> x).summaryStatistics();

		System.out.println("列表中最大的数 : " + stats.getMax());
		System.out.println("列表中最小的数 : " + stats.getMin());
		System.out.println("所有数之和 : " + stats.getSum());
		System.out.println("平均数 : " + stats.getAverage());
		System.out.println("随机数: ");
	}
}
